<?php


namespace app\test\controller;


use app\chat\LiveMessage;
use app\common\cachemodel\CouponCode;
use app\common\cachemodel\FortuneCache;
use app\common\cachemodel\live\LiveUserContribution;
use app\common\cachemodel\live\LiveZan;
use app\common\cachemodel\MonthFortune;
use app\common\cachemodel\Orders as OrdersCacheModel;
use app\common\cachemodel\OrdersLib;
use app\common\cachemodel\Recode;
use app\common\cachemodel\YearFortune;
use app\common\cachemodel\zl1_relation\Zl1RelationAnalysisReport;
use app\common\cachemodel\zlcr2\Zlcr2AstrTasks;
use app\common\cachemodel\zlcr2\Zlcr2UserQuestion;
use app\common\cachemodel\ZlcrAstr;
use app\common\cachemodel\ZlcrAstrAccount;
use app\common\cachemodel\ZlRecordShareAdd;
use app\common\cachemodel\ZlUserNoComment;
use app\common\cachemodel\ZlUserStarNumRecord;
use app\common\cachemodel\ZlUserVip;
use app\common\cachemodel\ZlVipBoon;
use app\common\cachemodel\ZlVipRanking;
use app\common\lib\Aes;
use app\common\lib\AliOss;
use app\common\lib\FortuneNewJob;
use app\common\lib\live\LiveCloseJob;
use app\common\lib\Push;
use app\common\lib\PushQueue;
use app\common\lib\SensorsDataSearch;
use app\common\lib\Util;
use app\common\lib\zlcr2\QuestionAnswerJob;
use app\common\model\User;
use app\common\service\Orders;
use app\pay\controller\Notify;
use think\Controller;
use think\Db;
use XznsTools\cache\CacheManage;
use XznsTools\curl\Curl;

class TestAction extends Controller
{
    public function test()
    {
        // $time = strtotime('2019-10-29');
        // FortuneCache::getUnlockFortune(10254508,553379,);
        // $a = FortuneCache::getUnlockFortune(10254508,553379,2);
        // $b = FortuneCache::CheckFortuneSevenUnlockStatus(10254508,553379,$time);
        // $c = FortuneCache::CheckFortuneMonthUnlockStatus(10254508,553379,$time);
        // (new ZlUserVip())->updateStarNum(12345215,8,0,38);
        // Util::queuePush('coupon_expire', 701,1000);

        // (new ZlVipBoon())->getBoonMessageString(1,[],2);
        // $times = date('Y-m-d H:i:s', strtotime('+1month'));
        // $orderModel = new OrdersCacheModel();
        // $orders = $orderModel->where(['order_id' => '03201911091128087469'])->column('uid,order_id,create_time,extend,status', 'id');

        // $str = 'http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLmyBYgmmBBMGw0IibSsx0kTKFibIhJPEGof82Bk4ZWmlpB4RvTD2Z1pmgbG1iarBshCsG1Yra6lurjQ/132';
        // $str1 = 'http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTI8WTXk7RbsqrtGH8OsYjvkpa3z6pDCicVxk4BvKnz5icrWrnNkH0SicNYXBK5IeFzeafQTJyhYcJKpA/132';
        //
        // $w = preg_match('/^http(s?):\/\/*/', $str);
        //
        // if (strpos($str, 'http') !== false)
        // {
        //     $sss = 1;
        //     // $a = Util::wxImgUploadOss($str1, 'uploads/avatar');
        // }

        // ZlUserVip::destroy(['uid'=>12345217]);
        // (new ZlVipRanking())->deleteRanking(12345214);
        // (new OrdersLib())->getUserVipTime(10254660, 35);
        // (new ZlUserVip())->updateStarNum(1,8,0,38);
        // $u = (new User())->getUserinfo(['id' => 17]);
        // (new ZlUserStarNumRecord())->getUserPercentOver(12345239);
        // (new Push())->pushUserMsg(10254660, '您的好友：zhs（准了号b443a57a44db）赠送您一张【日运免费券】已放入您的【卡券中心】快去使用吧~',['action' => 'discount_coupon_center'], '卡券获赠提醒');

        // 星力值更新及权益赠送 调用方法
        // $this->starNumUpdateAndSendBoon(12345346, 8, 0, 35, true);
        // $a = (new ZlUserNoComment())->where('uid',120)->find();
        // ZlUserNoComment::destroy(['uid'=>120]);
        // Db::table('wechat_backup_07_18_14_43_00.zl_user_no_comment')->where('delete_time', '<>', null)->select();
        // (new ZlUserVip())->updateStarNum(12345963, 9); // 绑定手机号任务

        // (new Notify())->wechat();
        $jdstr = '{
        "oid": 278660,
        "order_id": "02202104191610198034",
        "unlock_type": 1,
        "recode": {
            "4922519": {
                "id": 4922519,
                "status": 1,
                "name": "摸摸看",
                "type": 1,
                "year": 1995,
                "month": 3,
                "day": 9,
                "hour": 0,
                "minute": 3,
                "timezone": 8,
                "birth_country": "北京市",
                "birth_province": "北京市",
                "birth_city": "东城区",
                "live_country": "北京市",
                "live_province": "北京市",
                "live_city": "东城区",
                "comments": "自己",
                "isself": 1,
                "long_deg": 116,
                "long_min": 25,
                "ew": 1,
                "lat_deg": 39,
                "lat_min": 55,
                "ns": 1,
                "avatar": "",
                "is_summer": 0,
                "or_day": 9,
                "uid": 12346342,
                "aid": 4922829,
                "sun": "12-4-347.6184711",
                "moon": "3-7-69.4198601",
                "merc": "11-3-321.616589",
                "venu": "11-3-306.7602767",
                "mars": "5-9-134.8047972",
                "jupi": "9-1-254.508494",
                "satu": "12-4-345.3311997",
                "non": "8-12-218.2373952",
                "lili": "3-7-67.2069434",
                "juno": "9-2-269.2016055",
                "asc": "8-1-237.8968149",
                "mc": "6-10-161.6319834",
                "is_read": 1
            }
        },
        "start_time": [
            "2021"
        ],
        "type": "year",
        "status": 1,
        "push_switch": 1
    }';
        // $jobData = \GuzzleHttp\json_decode($jdstr,true);

        // $jobData = [
        //     'oid' => 0,
        //     'order_id' => 9113,
        //     'unlock_type' => 2, // 解锁类型 1=>订单解锁 2=>系统赠送
        //     'recode' => [4921035 => $recode],
        //     'start_time' => 0,
        //     'type' => 'month',
        //     'status' => 0,
        //     'push_switch' => 0
        // ];

        // (new FortuneNewJob())->fireData($jobData);

        // $recode = (new Recode())->getInfoById(4921035);
        // $recode = (new Recode())->getInfoById(4922519);
        // $data = (new YearFortune())->getFortuneYearDetail($recode, '2021');
        // $data = (new YearFortune())->getReocdeFortuneUnlockYears(4922519);
        // $data = (new YearFortune())->batchGetRecodeFortuneYearInfo(4922519,['2021']);
        // $data = (new MonthFortune())->batchGetRecodeFortuneMonthInfo(4921035, ['2022-06', '2022-07', '2022-08']);
        // $secret = '194d24499be7cc451f5b2be89d4fb33b6898783cf15fae6c19500d54677d2f09';
        // $res = Curl::request("https://xingzuonvshen.cloud.sensorsdata.cn/api/sql/query?token={$secret}&project=production", [
        //     'q' => 'select count(*) as a from user_group_user_group_1 limit 100',
        //     'format' => 'json'
        // ], 'POST', [], 'form_params');
        // $data1 = (new SensorsDataSearch())->getGroupList();
        // $data = (new SensorsDataSearch())->getQuerySearch('user_group_cg60twqdAmydad','','distinct_id',1,1000);
        // $str = '{"uid":12346342,"oid":278693}';
        // (new PushQueue())->Fortune(\GuzzleHttp\json_decode($str,true));

        // $h = '{"live_id":1,"action":"login","params":{"did":"EC21E9B9-8763-4626-B785-FF64574837E2","app-type":"ios","access-token":"QOFoKoGbSLoiR5/b0CMlKEHmSrpxUHx5rf16Il+kThuZAVhH3zU9IbAn5wAOYLlZjLbkPRpciqm0IAFBKTNa9w==","model":"iPhone 7 Plus","time":"1629539649","phone-version":"ios:12.4.1","version":"2.7.0","distinct-id":"5CE5EDAA-2A6E-4D89-ABA7-376CC40B2C45","sign":"KkzHDPmQm+bVGlH9DqB6WpwuXOn7tssMHO\/3muU6dJK3F2s8o7s7Hnwx3U1u28Gg9xknlrFEbY40cjx25SojxnYN+upvt6qtIV3Lp\/l+uRJ81B8FXUNWIzBeR8Undf8ONkxqAIZainBUCt1YfMNmneXMExxTSRR53BnLq6hMmfhiSM36OmSWRRobW7t3yJMv"}}';
        // $h = json_decode($h,true);
        // $a = LiveMessage::auth($h['params'],1);

        // $res = (new LiveUserContribution())->getContributionRanking(10185336,1,10);
        // $res = (new LiveUserContribution())->setLiveUserContributionValueInc(10185336,22222,50);

        // $map['id'] = input('id');
        // $userinfo = (new User())->getUserinfo($map);
        // $sign = 0;
        // if ($userinfo['rid'])
        // {
        //     $recordInfo = (new Recode())->getInfoById($userinfo['rid']);
        //     $sign = (int)(explode('-', $recordInfo['sun'])[0]);
        // }
        // echo $sign;

        // (new LiveCloseJob())->task(['live_id' => 10186336]);
        // (new Orders())->notify_handle('55202203042137459529', '1.99');

        // $taskId = (new Zlcr2AstrTasks())->where(['astr_id' => 55, 'qid' => '87057569922801'])->value('id');

        // (new ZlcrAstrAccount())->astrQuestionAnswerEarningsSend([
        //     'earning' => 0.556666788225,
        //     'total_amount' => 0.66,
        //     'astr_id' => 14,
        //     'type' => 1,
        //     'gid' => 77,
        //     'proportion' => 0.2,
        //     'question_type' => 2,
        //     'qid' => 'asda'
        // ]);
//        $oss = AliOss::getInstance();
//        $url = $oss->getAuth('/videos/20220511/71f8b52a4baea124d7bf42ee0916f40c.mp4');
        // (new QuestionAnswerJob())->AddQuestionReplyTimeoutCheck(['add_question_id' => 74]);
//        $astrTaskModel = new Zlcr2AstrTasks();
        // 获取已弃答次数
//        $discardNum = $astrTaskModel->getAstrDiscardQuestionNumByToday(175);
//        $res = (new Zl1RelationAnalysisReport())->getReportIsNew(12345883,2);
//        $res = (new Zl1RelationAnalysisReport())->reportRead(12345883,4,2);
        $res = (new Aes())->encryptWithOpenssl('000000');
        return show(config('code.success'), '请求成功', $res);
    }

    /**
     * 星力值更新及权益赠送
     * @param int $uid 用户ID
     * @param int $type 类型  1=>校准生辰 2=>日运 3=>月运 4=>年运 5=>幸运之城 6=>教学视频 7=>本命预测 8会员购买 9每日登陆 10每日幸运星 13绑定手机 14会员到期
     * @param $price 支付价格
     * @param int $gid 商品ID   35=>一个月VIP  36=>三个月VIP 37=>半年VIP 38=>一年VIP
     * @param bool $isSend 是否赠送权益
     * @throws \think\exception\PDOException
     * @throws \Exception
     */
    private function starNumUpdateAndSendBoon(int $uid, int $type, $price, int $gid, bool $isSend)
    {
        (new ZlUserVip())->updateStarNum($uid, $type, $price, $gid, false);

        if ($isSend)
        {
            (new ZlVipBoon())->vipBoonSend($uid);
        }

        echo '赠送完成';
    }

    public function index()
    {
        return $this->fetch();
    }

    public function resetCache()
    {
        $year = 2021;
        $cArr = [35, 36, 37, 38, 41, 40, 39];
        $redis = CacheManage::getInstance()->redisHandler;
        $num = [];
        foreach ($cArr as $id)
        {
            $data = (new CouponCode())->where('group_id', $id)->where('use_status', 0)->column('code');

            $cacheKey = 'year' . $year . ':activ:' . $id;
            $redis->delete($cacheKey);
            array_unshift($data, $cacheKey);

            call_user_func_array([$redis, 'lPush'], $data);
            // 初始化赠送数量 已经赠送
            $num[$id] = (new CouponCode())->where('group_id', $id)->where('use_status', '<>', 0)->count();

            $ruid = (new CouponCode())->where('group_id', $id)->where('use_status', 1)->column('uid');

            if ($ruid)
            {   // 初始化赠送用户ID
                array_unshift($ruid, 'year' . $year . ':activ_send_uid:' . $id);
                call_user_func_array([$redis, 'lPush'], $ruid);
            }
        }

        $redis->hMSet('year' . $year . ':activ_send_num', $num);
    }
}
